package com.itheima.mm.wx.service.impl;

import com.itheima.framework.annotation.HmComponent;
import com.itheima.mm.database.SqlSessionUtils;
import com.itheima.mm.pojo.Course;
import com.itheima.mm.pojo.Dict;
import com.itheima.mm.wx.dao.CourseDao;
import com.itheima.mm.wx.dao.DictDao;
import com.itheima.mm.wx.service.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author ：wanghao
 * @date ：Created in 2020/11/2
 * @description ：公共业务实现类
 * @version: 1.0
 */
@HmComponent("commonService")
@Slf4j
public class CommonServiceImpl implements CommonService {
    @Override
    public Dict findDictByCityName(String cityName) {
        SqlSession sqlSession = SqlSessionUtils.openSession();
        DictDao dictDao = sqlSession.getMapper(DictDao.class);
        Dict dict = dictDao.selectDictByCityName(cityName);
        sqlSession.close();
        return dict;
    }

    @Override
    public List<Dict> findDictListByFs(Integer fs) {
        SqlSession sqlSession = SqlSessionUtils.openSession();
        DictDao dictDao = sqlSession.getMapper(DictDao.class);
        List<Dict> dictList = dictDao.selectDictByFs(fs);
        sqlSession.close();
        return dictList;
    }

    @Override
    public List<Course> findCourseList() {
        SqlSession sqlSession = SqlSessionUtils.openSession();
        CourseDao courseDao = sqlSession.getMapper(CourseDao.class);
        List<Course> courseList = courseDao.selectCourseList();
        sqlSession.close();
        return courseList;
    }
}
